﻿@using Smartstore.Core.Catalog.Products

@model ProductModel

<input type="hidden" asp-for="OriginalStockQuantity" />

<div class="adminContent">

    <div class="adminRow">
        <div class="admin-config-group">
            <div class="head">@T("Admin.Catalog.Products.Fields.StockQuantity")</div>
        </div>
    </div>
    <div class="adminRow">
        <div class="adminTitle">
            <smart-label asp-for="ManageInventoryMethodId" />
        </div>
        <div class="adminData">
            <select asp-for="ManageInventoryMethodId" asp-items="ViewBag.AvailableManageInventoryMethods"></select>
            <span asp-validation-for="ManageInventoryMethodId"></span>
        </div>
    </div>
    <div class="adminRow" id="pnlStockQuantity">
        <div class="adminTitle">
            <smart-label asp-for="StockQuantity" />
        </div>
        <div class="adminData">
            <editor asp-for="StockQuantity" />
            <span asp-validation-for="StockQuantity"></span>
        </div>
    </div>
    <div class="adminRow" id="pnlDisplayStockAvailability">
        <div class="adminTitle">
            <smart-label asp-for="DisplayStockAvailability" />
        </div>
        <div class="adminData">
            <input asp-for="DisplayStockAvailability" data-toggler-for="#pnlDisplayStockQuantity" />
            <span asp-validation-for="DisplayStockAvailability"></span>
        </div>
    </div>
    <div class="adminRow" id="pnlDisplayStockQuantity">
        <div class="adminTitle">
            <smart-label asp-for="DisplayStockQuantity" />
        </div>
        <div class="adminData">
            <input asp-for="DisplayStockQuantity" />
            <span asp-validation-for="DisplayStockQuantity"></span>
        </div>
    </div>
    <div class="adminRow" id="pnlMinStockQuantity">
        <div class="adminTitle">
            <smart-label asp-for="MinStockQuantity" />
        </div>
        <div class="adminData">
            <editor asp-for="MinStockQuantity" />
            <span asp-validation-for="MinStockQuantity"></span>
        </div>
    </div>
    <div class="adminRow" id="pnlLowStockActivity">
        <div class="adminTitle">
            <smart-label asp-for="LowStockActivityId" />
        </div>
        <div class="adminData">
            <select asp-for="LowStockActivityId" asp-items="Html.GetLocalizedEnumSelectList(typeof(LowStockActivity))"></select>
            <span asp-validation-for="LowStockActivityId"></span>
        </div>
    </div>
    <div class="adminRow" id="pnlNotifyForQuantityBelow">
        <div class="adminTitle">
            <smart-label asp-for="NotifyAdminForQuantityBelow" />
        </div>
        <div class="adminData">
            <editor asp-for="NotifyAdminForQuantityBelow" />
            <span asp-validation-for="NotifyAdminForQuantityBelow"></span>
        </div>
    </div>
    <div class="adminRow" id="pnlBackorders">
        <div class="adminTitle">
            <smart-label asp-for="BackorderModeId" />
        </div>
        <div class="adminData">
            <select asp-for="BackorderModeId" asp-items="Html.GetLocalizedEnumSelectList(typeof(BackorderMode))"></select>
            <span asp-validation-for="BackorderModeId"></span>
        </div>
    </div>
    <div class="adminRow" id="pnlAllowBackInStockSubscriptions">
        <div class="adminTitle">
            <smart-label asp-for="AllowBackInStockSubscriptions" />
        </div>
        <div class="adminData">
            <input asp-for="AllowBackInStockSubscriptions" />
            <span asp-validation-for="AllowBackInStockSubscriptions"></span>
        </div>
    </div>

    <div class="adminRow">
        <div class="admin-config-group">
            <div class="head">@T("Admin.Catalog.Products.CartQuantity")</div>
            <div class="alert alert-info alert-dismissible fade show">
                <button type="button" class="btn-close" data-dismiss="alert"></button>
                @Html.Raw(ViewBag.CartQuantityInfo)
            </div>
        </div>
    </div>
    <div class="adminRow">
        <div class="adminTitle">
            <smart-label asp-for="OrderMinimumQuantity" />
        </div>
        <div class="adminData">
            <editor asp-for="OrderMinimumQuantity" />
            <span asp-validation-for="OrderMinimumQuantity"></span>
        </div>
    </div>
    <div class="adminRow">
        <div class="adminTitle">
            <smart-label asp-for="OrderMaximumQuantity" />
        </div>
        <div class="adminData">
            <editor asp-for="OrderMaximumQuantity" />
            <span asp-validation-for="OrderMaximumQuantity"></span>
        </div>
    </div>
    <div class="adminRow">
        <div class="adminTitle">
            <smart-label asp-for="QuantityStep" />
        </div>
        <div class="adminData">
            <editor asp-for="QuantityStep" />
            <span asp-validation-for="QuantityStep"></span>
        </div>
    </div>
    <div class="adminRow">
        <div class="adminTitle">
            <smart-label asp-for="AllowedQuantities" />
        </div>
        <div class="adminData">
            <input asp-for="AllowedQuantities" />
            <span asp-validation-for="AllowedQuantities"></span>
        </div>
    </div>
    <div class="adminRow">
        <div class="adminTitle">
            <smart-label asp-for="HideQuantityControl" />
        </div>
        <div class="adminData">
            <input asp-for="HideQuantityControl" />
            <span asp-validation-for="HideQuantityControl"></span>
        </div>
    </div>

</div>

<script>
    $(function () {
		$("#@Html.IdFor(model => model.ManageInventoryMethodId)").change(toggleManageStock);
		$("#@Html.IdFor(model => model.BackorderModeId)").change(toggleManageStock);

		toggleManageStock();

		function toggleManageStock() {
			var selectedManageInventoryMethodId = $("#@Html.IdFor(model => model.ManageInventoryMethodId)").val();

			if (selectedManageInventoryMethodId == '@((int)ManageInventoryMethod.DontManageStock)') {
				$('#pnlStockQuantity').hide();
				$('#pnlDisplayStockAvailability').hide();
				$('#pnlDisplayStockQuantity').hide();
				$('#pnlMinStockQuantity').hide();
				$('#pnlLowStockActivity').hide();
				$('#pnlNotifyForQuantityBelow').hide();
				$('#pnlAllowBackInStockSubscriptions').hide();
				$('#pnlBackorders').hide();
			}
			else if (selectedManageInventoryMethodId == '@((int)ManageInventoryMethod.ManageStock)') {
				$('#pnlStockQuantity').show();
				$('#pnlDisplayStockAvailability').show();

				if ($('#@Html.IdFor(model => model.DisplayStockAvailability)').is(':checked')) {
					$('#pnlDisplayStockQuantity').show();
				}
				else {
					$('#pnlDisplayStockQuantity').hide();
				}

				$('#pnlMinStockQuantity').show();
				$('#pnlLowStockActivity').show();
				$('#pnlNotifyForQuantityBelow').show();
				$('#pnlBackorders').show();
				var selectedBackorderModeId = $("#@Html.IdFor(model => model.BackorderModeId)").val();
				if (selectedBackorderModeId == '@((int)BackorderMode.NoBackorders)') {
					//no backorders
					$('#pnlAllowBackInStockSubscriptions').show();
				}
				else {
					//backorders are enabled
					$('#pnlAllowBackInStockSubscriptions').hide();
				}
			}
			else if (selectedManageInventoryMethodId == '@((int)ManageInventoryMethod.ManageStockByAttributes)') {
				$('#pnlStockQuantity').hide();
				$('#pnlDisplayStockAvailability').show();
				if ($('#@Html.IdFor(model => model.DisplayStockAvailability)').is(':checked')) {
					$('#pnlDisplayStockQuantity').show();
				}
				else {
					$('#pnlDisplayStockQuantity').hide();
				}
				$('#pnlMinStockQuantity').hide();
				$('#pnlLowStockActivity').hide();
				$('#pnlNotifyForQuantityBelow').hide();
				$('#pnlAllowBackInStockSubscriptions').hide();
				$('#pnlBackorders').hide();
			}
			else {
				$('#pnlStockQuantity').hide();
				$('#pnlDisplayStockAvailability').hide();
				$('#pnlDisplayStockQuantity').hide();
				$('#pnlMinStockQuantity').hide();
				$('#pnlLowStockActivity').hide();
				$('#pnlNotifyForQuantityBelow').hide();
				$('#pnlAllowBackInStockSubscriptions').hide();
				$('#pnlBackorders').hide();
			}
		}
	});
</script>